package control;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import javax.swing.DefaultListModel;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import model.Artigo;
import model.Pesquisador;

public class PesquisadorControle {

	public DefaultListModel<Pesquisador> pesquisadores() throws ParserConfigurationException, SAXException, IOException{
		DefaultListModel<Pesquisador> list = new DefaultListModel();
		
		for(int i=1; i<6; i++){
			
			File file = new File("curriculos\\"+i+".xml");
			
			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
			DocumentBuilder db = dbf.newDocumentBuilder();
			
			Document doc = db.parse(new InputSource(file.toString()));
			
			Element raiz = doc.getDocumentElement();
			
			
			String nome = ((Element)raiz.getElementsByTagName("DADOS-GERAIS").item(0)).
					getAttribute("NOME-COMPLETO");
			
			nome = new String(nome.getBytes("ISO-8859-1"), "UTF-8");
			
			ArrayList<Artigo> a = new ArrayList();
			
			Pesquisador p = new Pesquisador(nome, a, i);
			
			list.addElement(p);
			
		}
		
		return list;
	}
	
}
